In most of the cases you will write formulas that do not use the scripting features that NOV formulas provide. This is because the most common usage of formulas is to represent functional binding between multiple DOM properties (formulas are used in DOM formula expressions) or other values. There are cases however, when more complex formulas need to be authored and such cases are best solvable by using the scripting features present in NOV formulas.
The scripting abilities of NOV formulas aim to extend formulas with the following imperative programming language features:
- statements
- local variables
- scopes
Imperative programming languages are such languages that execute a sequence of statements that change a program state. Statements themselves are constructed by expressions. In NOV formulas you use the ';' (semi-colon) char to separate the statements. In most programming languages the statement is usually not associated with a return value, however in NOV formulas a sequence of statements returns the last expression evaluation result, since NOV formulas must always return a value. For example:
10;20;30 - returns 30.
Having the ability to execute a sequence of statements is useless, unless you have the means to store the result of previously executed statements (i.e. keep a program state). In NOV formulas this is achieved with local variables. Local variables are identifier tokens, to which you can assign a value by using the assignment operator. For example:
a=10;b=20;a+b - returns 30.
A local variable needs to first be assigned with a value prior to being used.
a=10;a+b - throws an "Evaluation error. Use of unassigned local variable with name:b"
Each NOV formula is associated with a root scope. The ever present root scope ensures that you can write formulas that consist of a sequence of statements. There are cases when you may want to create a child scope. A child scope is such an expression from the formula that is enclosed in '{' '}' (curly braces).
Just like the root scope, child scopes can contain multiple statements and return the last expression evaluation result, as result for the scope. Local variables however declared inside a child scope are not visible in its parent scope and sibling scopes, but are visible in its descendant scopes. For example:
a=10;{b=20};a+b - throws an "Evaluation error. Use of unassigned local variable with name:b", because b is declared in a child scope and is not visible to the root scope.
a=10;{b=20;a+b} - returns 30, because a is declared in the root scope and is visible in the child scope.